package Java网络编程;

import java.net.InetAddress;
import java.net.UnknownHostException;

/*InetAddress:Internet Protocol(IP)地址*/
public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        //getByName(String host)
        //确定主机名称的IP地址。

        //使用机器名称
//        InetAddress address = InetAddress.getByName("LAPTOP-OR4QOCL6");
        //使用IP地址
//        InetAddress address = InetAddress.getByName("192.168.189.1");
        InetAddress address = InetAddress.getByName("192.168.203.1");

        String name = address.getHostName();
        String ip = address.getHostAddress();
        System.out.println("主机名称："+name);
        System.out.println("IP地址："+ip);
    }
}
